﻿Imports DTO
Imports BUS
Public Class frmThamSo

    Private Sub FormThamSo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtSoLuongNhapToithieuMoi.Enabled = False
        txtSoLuongTonToiDaMoi.Enabled = False
        txtSoLuongTonToiThieuMoi.Enabled = False
        txtTienKhachHangNoToiDaMoi.Enabled = False


        txtSoLuongNhapToithieuMoi.Enabled = False
        txtSoLuongTonToiDaMoi.Enabled = False
        txtSoLuongTonToiThieuMoi.Enabled = False
        txtTienKhachHangNoToiDaMoi.Enabled = False
        Dim BangThamSo As BangThamSoDTO = ThamSoBUS.LayToanBoThamSo()
        txtSoLuongNhapToithieuCu.Text = BangThamSo.SoLuongNhapToiThieu.ToString()
        txtSoLuongTonToiThieuCu.Text = BangThamSo.SoLuongTonToiThieu.ToString()
        txtTienKhachHangNoToiDaCu.Text = BangThamSo.SoTienNoToiDa_KhachHang.ToString()
        txtSoLuongTonToiDaCu.Text = BangThamSo.SoLuongTonToiDa.ToString()

    End Sub

    Private Sub cbSoLuongNhapToiThieu_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSoLuongNhapToiThieu.CheckedChanged

        If cbSoLuongNhapToiThieu.Checked = True Then
            txtSoLuongNhapToithieuMoi.Enabled = True
        Else
            txtSoLuongNhapToithieuMoi.Enabled = False
        End If
    End Sub

    Private Sub cbSoLuongNhapToiDa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSoLuongNhapToiDa.CheckedChanged
        If cbSoLuongNhapToiDa.Checked = True Then
            txtSoLuongTonToiDaMoi.Enabled = True
        Else
            txtSoLuongTonToiDaMoi.Enabled = False
        End If
    End Sub

    Private Sub cbTienKhachHangNoToiDa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTienKhachHangNoToiDa.CheckedChanged
        If cbTienKhachHangNoToiDa.Checked = True Then
            txtTienKhachHangNoToiDaMoi.Enabled = True
        Else
            txtTienKhachHangNoToiDaMoi.Enabled = False
        End If
    End Sub

    Private Sub cbSoLuongTonToiThieu_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbSoLuongTonToiThieu.CheckedChanged
        If cbSoLuongTonToiThieu.Checked = True Then
            txtSoLuongTonToiThieuMoi.Enabled = True
        Else
            txtSoLuongTonToiThieuMoi.Enabled = False
        End If
    End Sub

    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        Dim ThamSo As BangThamSoDTO = New BangThamSoDTO()
        If txtSoLuongNhapToithieuMoi.Text <> "" Then
            ThamSo.SoLuongNhapToiThieu = Int32.Parse(txtSoLuongNhapToithieuMoi.Text)
        Else
            ThamSo.SoLuongNhapToiThieu = Int32.Parse(txtSoLuongNhapToithieuCu.Text)
        End If


        If txtSoLuongTonToiDaMoi.Text <> "" Then
            ThamSo.SoLuongTonToiDa = Int32.Parse(txtSoLuongTonToiDaMoi.Text)
        Else
            ThamSo.SoLuongTonToiDa = Int32.Parse(txtSoLuongTonToiDaCu.Text)
        End If


        If txtSoLuongTonToiThieuMoi.Text <> "" Then
            ThamSo.SoLuongTonToiThieu = Int32.Parse(txtSoLuongTonToiThieuMoi.Text)
        Else
            ThamSo.SoLuongTonToiThieu = Int32.Parse(txtSoLuongTonToiThieuCu.Text)
        End If

        If txtTienKhachHangNoToiDaMoi.Text <> "" Then
            ThamSo.SoTienNoToiDa_KhachHang = Double.Parse(txtTienKhachHangNoToiDaMoi.Text)
        Else
            ThamSo.SoTienNoToiDa_KhachHang = Double.Parse(txtTienKhachHangNoToiDaCu.Text)
        End If


        ThamSoBUS.CapNhatLaiBangThamSo(ThamSo)
        MessageBox.Show("Tham so da duoc cap nhật", "Thông Báo")

        txtSoLuongNhapToithieuCu.Text = ThamSo.SoLuongNhapToiThieu.ToString()
        txtSoLuongTonToiThieuCu.Text = ThamSo.SoLuongTonToiThieu.ToString()
        txtTienKhachHangNoToiDaCu.Text = ThamSo.SoTienNoToiDa_KhachHang.ToString()
        txtSoLuongTonToiDaCu.Text = ThamSo.SoLuongTonToiDa.ToString()

    End Sub
End Class